// @flow

import type {
  ServiceStatusApi,
  ServiceStatusSummary,
  Incident,
} from "@ledgerhq/live-common/lib/notifications/ServiceStatusProvider/types";

const statuses = {
  page: {
    id: "767c5rcj7z12",
    name: "Ledger",
    url: "https://status.ledger.com",
    time_zone: "Europe/Paris",
    updated_at: "2021-02-22T11:16:23.118+01:00",
  },
  components: [
    {
      id: "jz81k9469bqx",
      name: "Algorand (ALGO)",
      status: "operational",
      created_at: "2020-08-28T13:06:20.887+02:00",
      updated_at: "2021-02-07T01:00:45.574+01:00",
      position: 1,
      description: null,
      showcase: true,
      start_date: null,
      group_id: "rn7ny8423ghs",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "q0hxylcj2lkq",
      name: "Ledger Live Manager",
      status: "operational",
      created_at: "2020-06-04T15:10:17.966+02:00",
      updated_at: "2020-06-09T17:09:34.379+02:00",
      position: 1,
      description: null,
      showcase: false,
      start_date: null,
      group_id: null,
      page_id: "767c5rcj7z12",
      group: true,
      only_show_if_degraded: false,
      components: ["85dzpxj7ljrb", "hnts3r3j78sf"],
    },
    {
      id: "85dzpxj7ljrb",
      name: "Ledger Application Store",
      status: "operational",
      created_at: "2020-06-04T15:11:46.337+02:00",
      updated_at: "2020-12-12T00:51:58.772+01:00",
      position: 1,
      description: null,
      showcase: true,
      start_date: null,
      group_id: "q0hxylcj2lkq",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "z48wyk4p5y83",
      name: "Bitcoin Cash (BCH)",
      status: "operational",
      created_at: "2020-11-17T12:32:13.810+01:00",
      updated_at: "2021-02-21T17:14:52.035+01:00",
      position: 2,
      description: null,
      showcase: true,
      start_date: "2020-11-17",
      group_id: "rn7ny8423ghs",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "rn7ny8423ghs",
      name: "Ledger Explorers",
      status: "operational",
      created_at: "2020-06-04T16:28:33.644+02:00",
      updated_at: "2020-06-11T11:24:04.087+02:00",
      position: 2,
      description: null,
      showcase: false,
      start_date: null,
      group_id: null,
      page_id: "767c5rcj7z12",
      group: true,
      only_show_if_degraded: false,
      components: [
        "jz81k9469bqx",
        "z48wyk4p5y83",
        "pvy2kv7vxvkq",
        "h3rbmgvg3cc7",
        "ws5nf2ckdk09",
        "w1pd5b7q1xv5",
        "gj52364gdr2f",
        "l1k346mgsyql",
        "htq4b77zb1pq",
        "0h89nwm5lkzv",
        "nkqlqrrk0sz3",
        "p30d18l9wjl6",
        "981qckcn2l13",
        "44xfftm0ztkq",
        "98cy3t39mwy6",
        "t40n3pwhqqbq",
        "bbr3cn2lh5b7",
        "m6hmqxqph6xh",
        "btrnvtsvt91m",
        "s2ynmlxsxqn6",
        "b4rlmrcplprt",
        "lbx5pqlx95z4",
        "s0nb6pyz6phc",
        "mqsw7dfk04p6",
        "yts03zttvys2",
        "brwlnt1ymngj",
        "j6k0mvtp0nq8",
      ],
    },
    {
      id: "hnts3r3j78sf",
      name: "Ledger Live Security Services",
      status: "operational",
      created_at: "2020-06-11T11:39:59.141+02:00",
      updated_at: "2020-06-25T10:57:49.816+02:00",
      position: 2,
      description: null,
      showcase: true,
      start_date: null,
      group_id: "q0hxylcj2lkq",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "pvy2kv7vxvkq",
      name: "Bitcoin (BTC)",
      status: "operational",
      created_at: "2020-06-04T16:31:32.758+02:00",
      updated_at: "2021-01-07T17:57:15.158+01:00",
      position: 3,
      description: null,
      showcase: true,
      start_date: null,
      group_id: "rn7ny8423ghs",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "5nbgdl99n2tc",
      name: "Countervalue API",
      status: "operational",
      created_at: "2020-06-09T17:07:39.902+02:00",
      updated_at: "2020-12-17T15:46:07.647+01:00",
      position: 3,
      description: null,
      showcase: true,
      start_date: null,
      group_id: null,
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "h3rbmgvg3cc7",
      name: "Bitcoin Gold (BTG)",
      status: "operational",
      created_at: "2020-06-22T17:45:14.894+02:00",
      updated_at: "2021-01-06T06:03:15.234+01:00",
      position: 4,
      description: null,
      showcase: true,
      start_date: null,
      group_id: "rn7ny8423ghs",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "wgd35p84b89b",
      name: "Swap API",
      status: "operational",
      created_at: "2020-10-15T15:16:13.897+02:00",
      updated_at: "2021-02-03T13:31:39.254+01:00",
      position: 4,
      description: null,
      showcase: true,
      start_date: "2020-10-13",
      group_id: null,
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "ws5nf2ckdk09",
      name: "Cosmos (ATOM)",
      status: "operational",
      created_at: "2020-06-24T16:31:18.257+02:00",
      updated_at: "2021-02-19T14:20:08.413+01:00",
      position: 5,
      description: null,
      showcase: true,
      start_date: null,
      group_id: "rn7ny8423ghs",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "w8hy7c32lb4j",
      name: "Tezos Bakers API",
      status: "operational",
      created_at: "2020-06-22T18:02:19.597+02:00",
      updated_at: "2020-11-19T00:45:01.136+01:00",
      position: 5,
      description: null,
      showcase: true,
      start_date: null,
      group_id: null,
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "w1pd5b7q1xv5",
      name: "Dash (DASH)",
      status: "operational",
      created_at: "2020-06-22T17:45:51.432+02:00",
      updated_at: "2021-01-06T06:01:59.495+01:00",
      position: 6,
      description: null,
      showcase: true,
      start_date: null,
      group_id: "rn7ny8423ghs",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "gj52364gdr2f",
      name: "Decred (DCR)",
      status: "operational",
      created_at: "2020-06-22T17:46:28.456+02:00",
      updated_at: "2021-01-06T06:02:00.939+01:00",
      position: 7,
      description: null,
      showcase: true,
      start_date: null,
      group_id: "rn7ny8423ghs",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "l1k346mgsyql",
      name: "DigiByte (DGB)",
      status: "operational",
      created_at: "2020-06-22T17:46:58.999+02:00",
      updated_at: "2021-01-02T19:16:03.496+01:00",
      position: 8,
      description: null,
      showcase: true,
      start_date: null,
      group_id: "rn7ny8423ghs",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "htq4b77zb1pq",
      name: "Doge (DOGE)",
      status: "operational",
      created_at: "2020-06-22T17:48:10.105+02:00",
      updated_at: "2021-01-29T18:56:29.694+01:00",
      position: 9,
      description: null,
      showcase: true,
      start_date: null,
      group_id: "rn7ny8423ghs",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "0h89nwm5lkzv",
      name: "Ethereum Classic (ETC)",
      status: "operational",
      created_at: "2020-06-22T17:52:12.680+02:00",
      updated_at: "2021-02-10T18:52:59.332+01:00",
      position: 10,
      description: null,
      showcase: true,
      start_date: null,
      group_id: "rn7ny8423ghs",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "nkqlqrrk0sz3",
      name: "Ethereum (ETH)",
      status: "operational",
      created_at: "2020-06-22T17:49:26.907+02:00",
      updated_at: "2021-01-06T06:01:59.119+01:00",
      position: 11,
      description: null,
      showcase: true,
      start_date: null,
      group_id: "rn7ny8423ghs",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "p30d18l9wjl6",
      name: "Komodo (KMD)",
      status: "operational",
      created_at: "2020-06-22T17:52:32.379+02:00",
      updated_at: "2020-11-17T12:32:59.461+01:00",
      position: 12,
      description: null,
      showcase: true,
      start_date: null,
      group_id: "rn7ny8423ghs",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "981qckcn2l13",
      name: "Litecoin (LTC)",
      status: "operational",
      created_at: "2020-06-22T17:54:13.555+02:00",
      updated_at: "2021-02-10T20:48:33.039+01:00",
      position: 13,
      description: null,
      showcase: true,
      start_date: null,
      group_id: "rn7ny8423ghs",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "44xfftm0ztkq",
      name: "Pivx (PIVX)",
      status: "operational",
      created_at: "2020-06-22T17:55:04.800+02:00",
      updated_at: "2021-01-14T22:42:40.068+01:00",
      position: 14,
      description: null,
      showcase: true,
      start_date: null,
      group_id: "rn7ny8423ghs",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "98cy3t39mwy6",
      name: "Peercoin (PPC)",
      status: "operational",
      created_at: "2020-06-22T17:54:37.880+02:00",
      updated_at: "2021-01-06T06:04:31.097+01:00",
      position: 15,
      description: null,
      showcase: true,
      start_date: null,
      group_id: "rn7ny8423ghs",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "t40n3pwhqqbq",
      name: "Qtum (QTUM)",
      status: "operational",
      created_at: "2020-06-22T17:55:48.085+02:00",
      updated_at: "2021-01-06T06:03:47.929+01:00",
      position: 16,
      description: null,
      showcase: true,
      start_date: null,
      group_id: "rn7ny8423ghs",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "bbr3cn2lh5b7",
      name: "Stratis (STRAT)",
      status: "operational",
      created_at: "2020-06-22T17:56:58.493+02:00",
      updated_at: "2021-01-08T03:13:58.029+01:00",
      position: 17,
      description: null,
      showcase: true,
      start_date: null,
      group_id: "rn7ny8423ghs",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "m6hmqxqph6xh",
      name: "Tron (TRX)",
      status: "operational",
      created_at: "2020-06-22T18:00:50.351+02:00",
      updated_at: "2020-11-20T09:32:02.021+01:00",
      position: 18,
      description: null,
      showcase: true,
      start_date: null,
      group_id: "rn7ny8423ghs",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "btrnvtsvt91m",
      name: "Viacoin (VIA)",
      status: "operational",
      created_at: "2020-06-22T17:57:43.307+02:00",
      updated_at: "2021-01-29T16:44:54.451+01:00",
      position: 19,
      description: null,
      showcase: true,
      start_date: null,
      group_id: "rn7ny8423ghs",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "s2ynmlxsxqn6",
      name: "Vertcoin (VTC)",
      status: "operational",
      created_at: "2020-06-22T17:57:26.960+02:00",
      updated_at: "2021-01-06T06:02:00.112+01:00",
      position: 20,
      description: null,
      showcase: true,
      start_date: null,
      group_id: "rn7ny8423ghs",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "b4rlmrcplprt",
      name: "Stellar (XLM)",
      status: "operational",
      created_at: "2020-06-22T17:59:01.341+02:00",
      updated_at: "2021-02-16T17:59:41.452+01:00",
      position: 21,
      description: null,
      showcase: true,
      start_date: null,
      group_id: "rn7ny8423ghs",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "lbx5pqlx95z4",
      name: "Ripple (XRP)",
      status: "operational",
      created_at: "2020-06-22T18:00:26.785+02:00",
      updated_at: "2021-01-12T19:33:59.190+01:00",
      position: 22,
      description: null,
      showcase: true,
      start_date: null,
      group_id: "rn7ny8423ghs",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "s0nb6pyz6phc",
      name: "Stakenet (XSN)",
      status: "operational",
      created_at: "2020-06-22T17:56:05.389+02:00",
      updated_at: "2021-01-02T19:17:16.318+01:00",
      position: 23,
      description: null,
      showcase: true,
      start_date: null,
      group_id: "rn7ny8423ghs",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "mqsw7dfk04p6",
      name: "Stealthcoin (XST)",
      status: "operational",
      created_at: "2020-06-22T17:56:27.758+02:00",
      updated_at: "2021-02-12T08:40:20.583+01:00",
      position: 24,
      description: null,
      showcase: true,
      start_date: null,
      group_id: "rn7ny8423ghs",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "yts03zttvys2",
      name: "Tezos (XTZ)",
      status: "operational",
      created_at: "2020-06-22T18:01:12.765+02:00",
      updated_at: "2021-02-05T02:28:14.202+01:00",
      position: 25,
      description: null,
      showcase: true,
      start_date: null,
      group_id: "rn7ny8423ghs",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "brwlnt1ymngj",
      name: "Zcash (ZEC)",
      status: "operational",
      created_at: "2020-06-22T17:58:01.136+02:00",
      updated_at: "2021-01-29T18:17:55.041+01:00",
      position: 26,
      description: null,
      showcase: true,
      start_date: null,
      group_id: "rn7ny8423ghs",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
    {
      id: "j6k0mvtp0nq8",
      name: "Horizen (ZEN)",
      status: "operational",
      created_at: "2020-06-22T17:58:18.792+02:00",
      updated_at: "2021-01-06T06:01:47.835+01:00",
      position: 27,
      description: null,
      showcase: true,
      start_date: null,
      group_id: "rn7ny8423ghs",
      page_id: "767c5rcj7z12",
      group: false,
      only_show_if_degraded: false,
    },
  ],
  incidents: [],
  scheduled_maintenances: [],
  status: { indicator: "none", description: "All Systems Operational" },
};

const mockedIncidents: Incident[] = [
  {
    created_at: "2021-02-22T17:58:18.792+02:00",
    id: "incident-a",
    impact: "critical",
    incident_updates: [
      {
        body: "An incident occured",
        created_at: "2021-02-22T17:58:18.792+02:00",
        display_at: "2021-02-22T17:58:18.792+02:00",
        id: "incident-a-body",
        incident_id: "incident-a",
        status: "ongoing",
        updated_at: "2021-02-22T17:58:18.792+02:00",
      },
    ],
    monitoring_at: "2021-02-22T17:58:18.792+02:00",
    name: "Bitcoin network down",
    page_id: null,
    resolved_at: null,
    shortlink: "https://status.ledger.com/",
    status: "ongoing",
    updated_at: "2021-02-22T17:58:18.792+02:00",
    components: [{ name: "Bitcoin - Btc" }],
  },
  {
    created_at: "2021-02-22T17:58:18.792+02:00",
    id: "incident-b",
    impact: "critical",
    incident_updates: [
      {
        body: "An incident occured",
        created_at: "2021-02-22T17:58:18.792+02:00",
        display_at: "2021-02-22T17:58:18.792+02:00",
        id: "incident-a-body",
        incident_id: "incident-a",
        status: "ongoing",
        updated_at: "2021-02-22T17:58:18.792+02:00",
      },
    ],
    monitoring_at: "2021-02-22T17:58:18.792+02:00",
    name: "Generic status error",
    page_id: null,
    resolved_at: null,
    shortlink: "https://status.ledger.com/",
    status: "ongoing",
    updated_at: "2021-02-22T17:58:18.792+02:00",
  },
  {
    created_at: "2021-02-22T17:58:18.792+02:00",
    id: "incident-c",
    impact: "critical",
    incident_updates: [
      {
        body: "An incident occured",
        created_at: "2021-02-22T17:58:18.792+02:00",
        display_at: "2021-02-22T17:58:18.792+02:00",
        id: "incident-a-body",
        incident_id: "incident-a",
        status: "ongoing",
        updated_at: "2021-02-22T17:58:18.792+02:00",
      },
    ],
    monitoring_at: "2021-02-22T17:58:18.792+02:00",
    name: "Ehereum network down",
    page_id: null,
    resolved_at: null,
    shortlink: "https://status.ledger.com/",
    status: "ongoing",
    updated_at: "2021-02-22T17:58:18.792+02:00",
    components: [{ name: "Ethereum - Eth" }],
  },
];

export function toggleMockIncident(bool: boolean = true) {
  statuses.incidents = statuses.incidents.length > 0 ? [] : mockedIncidents;
}

export function resetIncidents() {
  statuses.incidents = [];
}

async function fetchStatusSummary(): Promise<ServiceStatusSummary> {
  return Promise.resolve(statuses);
}

const api: ServiceStatusApi = {
  fetchStatusSummary,
};

window.serviceStatusApi = {
  ...api,
  toggleMockIncident,
  resetIncidents,
};

export default api;
